
using QdbUnit;
using QdbUnit.Extensions.Fixtures;
using Qdb.Ext;
using Qdb.Foundation.IO;
using Qdb.Tests.Common.Exceptions;

namespace Qdb.Tests.Common.Exceptions
{
	public class BackupQdbIOExceptionTestCase : QdbIOExceptionTestCaseBase, IOptOutInMemory
	{
		public static void Main(string[] args)
		{
			new BackupQdbIOExceptionTestCase().RunAll();
		}

		private static readonly string BackupFile = "backup.qdb";

		/// <exception cref="System.Exception"></exception>
		protected override void QdbSetupBeforeStore()
		{
			base.QdbSetupBeforeStore();
			File4.Delete(BackupFile);
		}

		/// <exception cref="System.Exception"></exception>
		protected override void QdbTearDownBeforeClean()
		{
			base.QdbTearDownBeforeClean();
			File4.Delete(BackupFile);
		}

		public virtual void TestBackup()
		{
			Assert.Expect(typeof(QdbIOException), new _ICodeBlock_31(this));
		}

		private sealed class _ICodeBlock_31 : ICodeBlock
		{
			public _ICodeBlock_31(BackupQdbIOExceptionTestCase _enclosing)
			{
				this._enclosing = _enclosing;
			}

			/// <exception cref="System.Exception"></exception>
			public void Run()
			{
				this._enclosing.TriggerException(true);
				this._enclosing.Db().Backup(BackupQdbIOExceptionTestCase.BackupFile);
			}

			private readonly BackupQdbIOExceptionTestCase _enclosing;
		}
	}
}
